ePaper (IL3820) module Library  v0.5
Library for the 2.9-inch WaveShare ePaper display module
il3820_init.c
1 /*
2  * @file il3820_init.c
3  *
4  * @author Matthew Matz & Roy Eltham
5  *
6  * @version 0.5
7  *
8  * @copyright Copyright (C) Parallax, Inc. 2018. See end of file for
9  * terms of use (MIT License).
10  *
11  * @brief Waveshare ePaper display bitmap driver, see il3820_h. for documentation.
12  *
13  * @detail Please submit bug reports, suggestions, and improvements to
14  * this code to editor@parallax.com.
15  */
16 
17 
18 #include "il3820.h"
19 #include "simpletools.h"
20 
21 
22 char _sdi, _dc, _clk, _rst;
23 
24 
25 screen_t *il3820_init(char sdi, char sclk, char cs, char rs, char rst, char busy, int _width, int _height) {
26 
27  screen_t* dev = (screen_t*) malloc(sizeof(screen_t));
28  memset(dev, 0, sizeof(screen_t));
29 
30  unsigned char* _image = (char*) malloc(_width * ((_height + 7) >> 3));
31  memset(_image, 0xff, (_width * ((_height + 7) >> 3)));
32 
33  dev->color_depth = 1; // Set the color depth to monochrome
34 
35  dev->image_ptr = _image;
36  dev->image_size = (_width * ((_height + 7) >> 3));
37 
38  dev->dc_pin = rs;
39  dev->sdi_pin = sdi;
40  dev->clk_pin = sclk;
41  dev->rst_pin = rst;
42 
43  dev->dev_id = cs;
44  dev->status_pin = busy;
45 
46  dev->width = _width;
47  dev->height = _height;
48  dev->text_size = 1;
49  dev->text_wrap = 1;
50  dev->text_color = BLACK;
51  dev->bg_color = BLACK;
52  dev->color_depth = 1;
53 
54  dev->deviceDrawPixel = il3820_drawPixel;
55  dev->deviceDrawFastHLine = il3820_drawFastHLine;
56  dev->deviceDrawFastVLine = il3820_drawFastVLine;
57 
58  dev->deviceInterface = INTF_SPI_WITH_BUFFER; // interface type (bit 1) (1-i2c/0-SPI) and buffer (bit 0) (0-yes/1-no)
59 
60  dev->deviceClearDisplay = il3820_clearDisplay;
61  dev->deviceUpdateDisplay = il3820_updateDisplay; // Use if display needs to be updated (otherwise 0)
62  dev->deviceResetDisplay = il3820_resetDisplay;
63 
64  i2c *eeBus = i2c_newbus(28, 29, 0);
65  loadFonts(dev, eeBus);
66 
67  // set pin directions
68  set_direction(cs, 1);
69  set_direction(rst, 1);
70  set_direction(rs, 1);
71  set_direction(sdi, 1);
72  set_direction(sclk, 1);
73  set_direction(busy, 0);
74 
75  il3820_resetDisplay(dev);
76  il3820_clearDisplay(dev);
77  il3820_updateDisplay(dev); // Updates the display a second time to eliminate any ghosting from prior drawings
78 
79  return dev;
80 }
81 
82 
83 
84 
85